package interfacetest;

import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.List;

public class Main {

	public static void main(String[] args) {
		//test1();
//		getReflectAllMethod(TestInterface.class);
		new TestCase1();
		//new TestCase();
		
		new TestCase2();
		TestCase testCase=new TestCase();
		testCase.setTestNUll();
	}

	public static void test1(){
		List<Class<?>> allInterface = ClassUtil.getAllClassByInterface(TestInterface.class);
		for (Class<?> class1 : allInterface) {
			try {
				TestInterface c = (TestInterface) class1.newInstance();
				c.print();
			} catch (InstantiationException | IllegalAccessException e) {
				e.printStackTrace();
			}
		}
	}
	
	public static void test() {
		try {
			System.out.println("接口实现类：");
			for (Class<?> c : ClassUtil.getAllAssignedClass(TestInterface.class)) {
				System.out.println(c.getName());
			}
			System.out.println("子类：");
			for (Class<?> c : ClassUtil.getAllAssignedClass(TestInterface.class)) {
				System.out.println(c.getName());
			}
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/***
	 *  获取java类中所有方法及其参数
	 * @param mLocalClass
	 */
	public static void getReflectAllMethod(Class<?> mLocalClass) {
		Class<?> c = mLocalClass;
		try {
			do {
				Method m[] = c.getDeclaredMethods(); // 取得全部的方法
				for (int i = 0; i < m.length; i++) {
					String mod = Modifier.toString(m[i].getModifiers()); // 取得访问权限
					String metName = m[i].getName(); // 取得方法名称
					Class<?> ret = m[i].getReturnType();// 取得返回值类型
					Class<?> param[] = m[i].getParameterTypes(); // 得到全部的参数类型
					Class<?> exc[] = m[i].getExceptionTypes(); // 得到全部的异常
					System.out.print(mod + " ");// 输出每一方法的访问权限
					System.out.print(ret + " ");// 输出每一方法的返回值类型
					System.out.print(metName + " (");// 输出每一方法的名字
					for (int x = 0; x < param.length; x++) {// 循环输出每一方法的参数的类型
						System.out.print(param[x] + "arg-" + x);
						if (x < param.length - 1) {
							System.out.print(",");
						}
					}
					System.out.print(") ");
					if (exc.length > 0) {// 有异常抛出
						System.out.print("throws ");
						for (int x = 0; x < exc.length; x++) {// 循环输出每一方法所抛出的异常名字
							System.out.print(exc[x].getName());
							if (x < param.length - 1) {
								System.out.print(",");
							}
						}
					}
					System.out.println();
				}
				c = c.getSuperclass();
			} while (c != null);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
